-
Notifications
You must be signed in to change notification settings - Fork 655
New thread pool #4635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
New thread pool #4635
Conversation
|
CI MESSAGE: [7183171]: BUILD STARTED |
|
CI MESSAGE: [7183171]: BUILD FAILED |
|
CI MESSAGE: [7189340]: BUILD STARTED |
|
CI MESSAGE: [7189340]: BUILD PASSED |
f0d76a6 to
d74ec03
Compare
d74ec03 to
f5bcae4
Compare
a181cde to
70deb50
Compare
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
466d38d to
e053ff7
Compare
86c7337 to
f2a437f
Compare
aedb85c to
ced7133
Compare
|
CI MESSAGE: [41172120]: BUILD STARTED |
|
CI MESSAGE: [41172120]: BUILD FAILED |
|
CI MESSAGE: [41183936]: BUILD STARTED |
|
CI MESSAGE: [41184260]: BUILD STARTED |
|
CI MESSAGE: [41187088]: BUILD STARTED |
|
CI MESSAGE: [41187088]: BUILD FAILED |
|
CI MESSAGE: [41571534]: BUILD STARTED |
|
CI MESSAGE: [41571534]: BUILD FAILED |
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
… a job object, reexposing the legacy thread pool interface. Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
Signed-off-by: Michal Zientkiewicz <[email protected]>
|
CI MESSAGE: [41726080]: BUILD STARTED |
Signed-off-by: Michal Zientkiewicz <[email protected]>
|
CI MESSAGE: [41727400]: BUILD STARTED |
Greptile SummaryThis PR introduces a new thread pool implementation ( Key implementation details:
The code is well-structured with comprehensive tests covering basic operations, error handling, reentrancy, and incremental job execution. The synchronization primitives are used correctly throughout. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Job
participant ThreadPoolBase
participant Semaphore
participant WorkerThread
participant Task
Note over Client,Task: Normal Job Execution Flow
Client->>Job: AddTask(runnable, priority)
Job->>Job: Store in tasks_ multimap (sorted by priority)
Client->>Job: Run(tp, wait=true)
Job->>ThreadPoolBase: BeginBulkAdd()
ThreadPoolBase-->>Job: TaskBulkAdd object
loop For each task (by priority)
Job->>ThreadPoolBase: batch.Add(task)
ThreadPoolBase->>ThreadPoolBase: AddTaskNoLock() [mutex held]
ThreadPoolBase->>ThreadPoolBase: tasks_.push()
end
Job->>ThreadPoolBase: batch.Submit() [destructor]
ThreadPoolBase->>Semaphore: release(tasks_added)
Semaphore-->>WorkerThread: wake up
WorkerThread->>Semaphore: acquire()
WorkerThread->>ThreadPoolBase: PopAndRunTask()
ThreadPoolBase->>Task: execute()
Task->>Job: decrement num_pending_tasks_
alt Last task completed
Task->>Job: DoNotify()
Job->>Job: num_pending_tasks_.notify_all()
Job->>Job: cv_.notify_all()
Job->>Job: running_ = false
end
Job->>Job: Wait()
alt Called from thread pool
Job->>ThreadPoolBase: WaitOrRunTasks(cv_, condition)
Note over ThreadPoolBase: Reentrant: execute tasks while waiting
loop Until condition met
ThreadPoolBase->>ThreadPoolBase: PopAndRunTask()
end
else Called from external thread
Job->>Job: num_pending_tasks_.wait()
Note over Job: Atomic wait on counter
end
Job-->>Client: Return (rethrow errors if any)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, 1 comment
|
CI MESSAGE: [41726080]: BUILD FAILED |
Signed-off-by: Michal Zientkiewicz <[email protected]>
|
CI MESSAGE: [41730522]: BUILD STARTED |
Category:
New feature (non-breaking change which adds functionality)
Description:
This PR introduces a new thread pool object that will eventually replace the current thread pool.
This thread pool separates the definition of work (called a Job) from the runner threads, allowing multiple concurrent jobs to share one pool of threads.
There are two types of job:
JobandIncrementalJob.The former must be fully defined before it is submitted to the thread pool. The tasks in this kind of job have priorities.
The latter can be submitted in parts. This precludes sorting (once submitted to the thread pool, the tasks are processed in FIFO order).
The thread pool allows for some overlap between jobs, although when a job is submitted, all of its task will be picked up for execution before any tasks from any subsequent job.
After submitting a job, the job owner has to wait for the job to complete.
The new thread pool is reentrant - it is legal to submit and wait for a sub-job from inside a thread pool task. This scenario is detected automatically ant the Wait function cooperatively executes the tasks from the thread pool until the inner job completes.
Additional information:
The thread pool uses a plain
std::queuefor task storage and a counting semaphore (POSIX) and amutexfor synchronization.The job uses an atomic counter of outstanding tasks and atomic_wait to wait for completion.
Affected modules and functionalities:
None. This is entirely new code that doesn't affect any existing functionality yet.
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-864